# Figure D1: Effect of Covid-19 on Asian hate crimes by quartile of share of workers in affected economic sectors

rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(estimatr)
library(ggplot2)
library(dplyr)


if (!file.exists('./output/out_econ_quantiles.RData')) {
  source('./code/figureD1reg.R')
}

load('./output/out_econ_quantiles.RData')

out <- rbind(
  tidy(out_econ_25_con_trend_all) %>% filter(term=='covid_econ_25') %>% select(estimate, conf.low, conf.high),
  tidy(out_econ_con_trend_all) %>% filter(term=='covid_econ') %>% select(estimate, conf.low, conf.high),
  tidy(out_econ_50_con_trend_all) %>% filter(term=='covid_econ_75') %>% select(estimate, conf.low, conf.high)
)

types <- data.frame(treat = c('Q1', 'Q2', 'Q3'))

out <- cbind(out,types)

out %>% ggplot() + aes(x = treat, y = estimate) +
  geom_point() +
  geom_hline(yintercept = 0, colour='#999999', linetype='longdash') + 
  geom_linerange(aes(ymin = conf.low, ymax = conf.high)) +
  #scale_y_continuous(breaks=c(-10,0,10,20,30,40,50,60)) +
  theme(
    legend.position="bottom", legend.title = element_blank(), legend.text = element_text(size = 12),
    panel.grid.major = element_blank(),
    panel.grid.minor = element_blank(),
    panel.background = element_blank(), axis.line = element_line(colour = "black"
    ),axis.title.y = element_text(size = rel(1.2)), axis.text.x=element_text(size=14),axis.text.y=element_text(size=12)) +
  xlab(NULL) +
  ylab('Unemployment effects of Covid-19 on hate crimes')
ggsave('./econ_effects_by_quartile.pdf', width=6, height=4.85)